package com.player;

import java.io.File;
import java.io.IOException;

import javax.media.CannotRealizeException;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;

public class MyPlayer implements ControllerListener {

	Player player;

	@Override
	public void controllerUpdate(ControllerEvent pArg0) {
		if (pArg0 instanceof PrefetchCompleteEvent) {
			player.start();
			return;
		}


	}

	public void play() {
		File file = new File("d://TX.mp3");
		MediaLocator locator = new MediaLocator("file:///"
				+ file.getAbsolutePath());
			try {
				player = Manager.createRealizedPlayer(locator);
			} catch (IOException e) {
				e.printStackTrace();
			} catch (NoPlayerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (CannotRealizeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
		
		player.addControllerListener(this);
		player.prefetch();
	}

	public void stop() {
		// TODO Auto-generated method stub
		player.stop();
	}

}
